package database.team.generator;
import java.io.BufferedWriter;
import java.io.FileWriter;
import java.io.IOException;
import java.text.DecimalFormat;
import java.util.Random;
import java.util.Scanner;


public class tableGenerator {
	private static DecimalFormat df = new DecimalFormat("#.##");
	
	public static void main(String[] args)
	{
		Scanner scanner = new Scanner(System.in);
		
		try{
			System.out.println("enter the no. of records you want to generate the table Emp_Dept");
			int numberOfRecords = scanner.nextInt();
			System.out.println("generating the file...");
			generateFileWith(numberOfRecords);
			System.out.println("generated the file with "+numberOfRecords+" records");
			
			
		}
		catch(IOException e){
			e.printStackTrace();
			
			}
		
	}
	public static void generateFileWith(int numberOfRecords) throws IOException
	{
			 BufferedWriter fbw = new BufferedWriter(new FileWriter("Emp-Dept.txt"));
			 for(int i = 0; i < numberOfRecords; i++)
			 {
				 fbw.write("" + generateRecord());
				 fbw.newLine();
			 }
			 fbw.close();
	
	}
	
	public static String generateRecord()
	{
		int Emp_ID=0;
		String Department=null ;
		String valueSal = null;
		String valuePart = null;
		int Salary=0;
		int decPart = 0;
		String memo=null;
		char alphabets[] = {'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','r','s','t','u','v','w','x','y','z'};
		
		Emp_ID = (int)(Math.random()*1000000);
		//to assure length of Emp_ID is 7
		if (Emp_ID<1000000)
		{
			Emp_ID = Emp_ID + 1000000;
		}
		Department = generateString(alphabets,11);
		Random r = new Random();
		//double randomSalary = 3000 + (10000000 - 3000) * r.nextDouble();
		double randomSalary = r.nextDouble() * 100000000.0;
		String randomSalaryString = df.format(randomSalary);
		memo=generateString(alphabets,70);
		String record=(Emp_ID+Department+randomSalaryString+memo);
		return record;
	
	}
	
	public static String generateString(char alphabets[],int length)
	{
		
		String value="";
		for (int i=0;i<(length-1);i++)
		{
			int randomNumber=(int)(Math.random()*25);
			value=value+alphabets[randomNumber];
		}
		return value;
	}

}
